﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraRotateAround : MonoBehaviour
{
    //注意，测试的时候，先让摄像机  Ctel+Shift+F   对准这个物体
    public Transform centerTf;

    private void Update()
    {
        //如果同时按住左Alt+鼠标左键  就围绕旋转
        if (Input.GetKey(KeyCode.LeftAlt) && Input.GetMouseButton(0))
        {
            //获取鼠标滑动增量
            float mx = Input.GetAxis("Mouse X");
            float my = Input.GetAxis("Mouse Y");

            //围绕up轴旋转
            transform.RotateAround(centerTf.position, Vector3.up, 180 * Time.deltaTime * mx);

            //围绕摄像机自己x轴旋转
            transform.RotateAround(centerTf.position, transform.right, 180 * Time.deltaTime * -my);
        }
    }
}